package com.tj.pystandard.tjapi.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * 解决RedisDeskManager乱码问题
 *
 * @author qiuting
 * @date 2020/11/5 14:53
 */
@Configuration
public class RedisConfig {
	@Autowired
	private RedisTemplate redisTemplate;

	@Bean
	public RedisTemplate redisTemplateInit() {
		StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
		GenericJackson2JsonRedisSerializer jsonRedisSerializer = new GenericJackson2JsonRedisSerializer();
		//设置序列化Key的实例化对象
		redisTemplate.setKeySerializer(stringRedisSerializer);
		redisTemplate.setHashKeySerializer(stringRedisSerializer);
		//设置序列化Value的实例化对象
		redisTemplate.setValueSerializer(jsonRedisSerializer);
		redisTemplate.setHashValueSerializer(jsonRedisSerializer);
		return redisTemplate;
	}
}
